//
//  CookBookMoreTableViewCell.m
//  Taste
//
//  Created by 徐昊 on 16/9/20.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "CookBookMoreTableViewCell.h"
#import "ImageAndLabelCollectionViewCell.h"
#import "HXMacro.h"
#import "MasterCookBookMore.h"
#import "MasterCookBookViewController.h"

#define kHomePageCollectionViewImageAndLabelCellName @"HomePageCollectionViewImageAndLabelCellReuse"
@interface CookBookMoreTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;

@end

@implementation CookBookMoreTableViewCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    _layout.minimumInteritemSpacing = 5;
    _layout.minimumLineSpacing = 5;
    _layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    _collectionView.scrollEnabled = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [_collectionView registerNib:[UINib nibWithNibName:@"ImageAndLabelCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:kHomePageCollectionViewImageAndLabelCellName];
}
- (void)setArray:(NSMutableArray<MasterCookBookMore *> *)array {
    _array = array;
    [_collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ImageAndLabelCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kHomePageCollectionViewImageAndLabelCellName forIndexPath:indexPath];
    cell.cookBookMore = _array[indexPath.row];
    cell.label.numberOfLines = 2;
    cell.label.font = [UIFont systemFontOfSize:15];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    _layout.itemSize = CGSizeMake((SCREEN_WIDTH - 20) / 3, (SCREEN_WIDTH - 20) / 3 + 40);
    return _layout.itemSize;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    MasterCookBookViewController *vc =[[MasterCookBookViewController alloc] init];
    MasterCookBookViewController *homeVC = (MasterCookBookViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder;
    vc.numString = _array[indexPath.row].masterCookBookMore_id;
    [homeVC.navigationController pushViewController:vc animated:YES];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
